import featuretools as ft
import pandas as pd

# 创建一个示例数据集
data = {
    'order_id': [1, 2, 3, 4, 5],
    'customer_id': [1, 1, 2, 2, 3],
    'order_date': ['2022-01-01', '2022-01-03', '2022-01-02', '2022-01-04', '2022-01-05'],
    'order_amount': [100, 150, 200, 250, 300]
}

orders_df = pd.DataFrame(data)

# 创建一个实体集
es = ft.EntitySet(id='orders')

# 添加实体
es = es.add_dataframe(entity_id='orders',
                               dataframe=orders_df,
                               index='order_id',
                               time_index='order_date')

# 定义特征集
feature_matrix, feature_defs = ft.dfs(entityset=es,
                                       target_entity='orders',
                                       agg_primitives=['sum', 'mean'],
                                       trans_primitives=['month', 'day'])

print(feature_matrix)
